package com.example.mywechat;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class AddAddress extends AppCompatActivity {
    private MyDAO myDAO = new MyDAO(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_address);
        Button add_phone_btn = findViewById(R.id.bt_add_phone);
        add_phone_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addPhone();
                Intent it=new Intent(AddAddress.this,MainActivity.class);
                startActivityForResult(it, 1);
                System.out.println("退出了！");
                finish();
            }
        });
    }


    //添加一个通讯录电话
    private void addPhone(){
        EditText  et_Name = (EditText)this.findViewById(R.id.etxt_name);
        EditText et_Tel = (EditText)this.findViewById(R.id.etxt_tel);
        String p1 = et_Name.getText().toString();
        String p2 = et_Tel.getText().toString();
        Log.d("p1 = ",p1);
        Log.d("p2 = ",p2);
        if(p1.equals("")||p2.equals("")){  //要求输入了信息
            Toast.makeText(getApplicationContext(),"姓名和电话都不能空！",Toast.LENGTH_SHORT).show();
        }else{
            myDAO.insertInfo(p1, p2);  //第2参数转型
            Toast.makeText(getApplicationContext(),"添加成功！",Toast.LENGTH_SHORT).show();
        }
    }

}
